// let p = new Promise(function (resolve, reject) {
//   setTimeout(function () {
//     resolve(11)
//   }, 1000)
// })


// p.then(res => {
//   console.log(res)
// })


// 实现简单的promise


class PromiseM {
  constructor(process) {
    this.status = "pending"
    this.msg = ""
    process(this.resolve.bind(this), this.reject.bind(this))
    return this
  }
  resolve(val) {
    this.status = 'fulfilled'
    this.msg = val
  }
  reject(val) {
    this.status = 'rejected'
    this.msg = val
  }
  then(fufilled, reject) {
    if (this.status === 'fulfilled') {
      fufilled(this.msg)
    }
    if (this.status === 'rejected') { reject(this.msg) }
  }

}

let p = new PromiseM(function (resolve, reject) {
  resolve(111)
});

p.then((res) => {
  console.log(res);
})